package zunyi04;

public class CheckAccount extends Account{

    private double overdraft;//可透支额

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }

    public CheckAccount(int id, double balance, double annualInterRate, double overdraft) {
        super(id, balance, annualInterRate);
        this.overdraft = overdraft;
    }

    public CheckAccount() {
        super();
    }

    public void withdraw(double amount) {

        if (amount < getBalance()) {
            double am = getBalance() - amount;
            balance=am;//账户余额
            System.out.println("您的账户余额为：" + balance);
            System.out.println("您的可透支额为：" + getOverdraft());
        }
        if (amount >getBalance()) {

            if (amount < getBalance() + getOverdraft()) {

                double Over = getBalance() + getOverdraft() - amount; //计算透支金额
                setBalance(0); //竟然透支了直接将余额赋值为零
                overdraft=Over;//透支额
                System.out.println("您的账户余额为：" +getBalance());
                System.out.println("您的可透支额为：" + overdraft);
            } else {
                System.out.println("超过可透支额！");
            }
        }
    }
}
